package cn.mitool.crypto.codec;

import java.nio.charset.StandardCharsets;

/**
 * Base32
 *
 * @author dragon
 * @version 1.0
 * @date 2024/7/10 13:56
 */
public class Base32 {

    /**
     * Base32编码
     *
     * @param data 数据
     * @return Base32编码字符串
     */
    public static String encode(String data) {
        return encode(data.getBytes(StandardCharsets.UTF_8));
    }

    /**
     * Base32编码
     *
     * @param data 数据
     * @return Base32编码字符串
     */
    public static String encode(byte[] data) {
        org.apache.commons.codec.binary.Base32 base16 = new org.apache.commons.codec.binary.Base32();
        return new String(base16.encode(data));
    }

    /**
     * Base32解码
     *
     * @param data 数据
     * @return Base32解码字符串
     */
    public static String decode(String data) {
        return decode(data.getBytes(StandardCharsets.UTF_8));
    }

    /**
     * Base32解码
     *
     * @param data 数据
     * @return Base32解码字符串
     */
    public static String decode(byte[] data) {
        org.apache.commons.codec.binary.Base32 base16 = new org.apache.commons.codec.binary.Base32();
        return new String(base16.decode(data));
    }

}
